package io.sqrtqiezi.spark.udaf

import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.functions._

object BoolAndTest extends App {
  val spark = SparkSession
    .builder()
    .master("local")
    .appName("aggregate practise")
    .getOrCreate()

  val and = new BoolAnd
  spark.udf.register("booland", and)

  val df = spark.range(1)
    .selectExpr("explode(array(TRUE, TRUE, TRUE)) as t")
    .selectExpr("explode(array(TRUE, FALSE, TRUE)) as f", "t")

  df.show

  df.agg(and(col("t")), expr("booland(f)"))
    .show
}
